import 'package:basic_ui/constants/app_sizes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:insail_flutter_boot_template/feature/auth/data/providers/auth_provider.dart';
import 'package:insail_flutter_boot_template/routing/app_router.dart';

class CustomSignInScreen extends ConsumerWidget {
  const CustomSignInScreen({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final authRepository = ref.watch(customAuthProviderProvider);

    return Scaffold(
      appBar: AppBar(title: const Text("Sign In")),
      body: Center(
        child: Column(
          children: [
            TextField(
                controller: TextEditingController(),
                decoration: const InputDecoration(labelText: "Email")),
            TextField(
                controller: TextEditingController(),
                decoration: const InputDecoration(labelText: "Password")),
            ElevatedButton(
              onPressed: () async {
                await authRepository.signInWithEmailAndPassword(
                    'test@example.com', 'password');
                context.goNamed(AppRoute.profile.name);
              },
              child: const Text("Sign In with Email"),
            ),
            ElevatedButton(
              onPressed: () async {
                await authRepository.signInWithPhone('13627482033', 'password');
              },
              child: const Text("Sign In with Phone"),
            ),
          ],
        ),
      ),
    );
  }
}

class SignInAnonymouslyFooter extends ConsumerWidget {
  const SignInAnonymouslyFooter({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Column(
      children: [
        gapH8,
        const Row(
          children: [
            Expanded(child: Divider()),
            Padding(
              padding: EdgeInsets.symmetric(horizontal: Sizes.p8),
              child: Text('or'),
            ),
            Expanded(child: Divider()),
          ],
        ),
        TextButton(
          // onPressed: () => ref.read(firebaseAuthProvider).signInAnonymously(),
          onPressed: () {},
          child: const Text('Sign in anonymously'),
        ),
      ],
    );
  }
}
